package com.fr.report.highlight;

import com.fr.base.FRFont;
import com.fr.base.Style;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.CellElement;
import com.fr.report.Report;
import com.fr.report.script.Calculator;
import java.awt.Color;
import java.util.Iterator;

public class ForegroundHighlightAction extends AbstractHighlightAction
{
  private Color foregroundColor = Color.black;
  private int scope = 0;

  public ForegroundHighlightAction()
  {
  }

  public ForegroundHighlightAction(Color paramColor, int paramInt)
  {
    this.foregroundColor = paramColor;
    this.scope = paramInt;
  }

  public Color getForegroundColor()
  {
    return this.foregroundColor;
  }

  public void setForegroundColor(Color paramColor)
  {
    this.foregroundColor = paramColor;
  }

  public int getScope()
  {
    return this.scope;
  }

  public void setScope(int paramInt)
  {
    this.scope = paramInt;
  }

  public void action(CellElement paramCellElement, Calculator paramCalculator)
  {
    if (paramCellElement == null)
      return;
    Report localReport = paramCalculator.getCurrentReport();
    switch (getScope())
    {
    case 1:
      if (localReport == null)
        return;
      int i = paramCellElement.getRow();
      Iterator localIterator1 = localReport.getRow(i);
      while (true)
      {
        if (!(localIterator1.hasNext()))
          return;
        modifyForeground((CellElement)localIterator1.next(), this.foregroundColor);
      }
    case 2:
      if (localReport == null)
        return;
      int j = paramCellElement.getColumn();
      Iterator localIterator2 = localReport.getColumn(j);
      while (true)
      {
        if (!(localIterator2.hasNext()))
          return;
        modifyForeground((CellElement)localIterator2.next(), this.foregroundColor);
      }
    }
    modifyForeground(paramCellElement, this.foregroundColor);
  }

  private void modifyForeground(CellElement paramCellElement, Color paramColor)
  {
    if (paramCellElement == null)
      return;
    Style localStyle = paramCellElement.getStyle();
    FRFont localFRFont = localStyle.getFRFont();
    localFRFont = localFRFont.applyForeground(paramColor);
    paramCellElement.setStyle(localStyle.deriveFRFont(localFRFont));
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof ForegroundHighlightAction))
      return false;
    ForegroundHighlightAction localForegroundHighlightAction = (ForegroundHighlightAction)paramObject;
    return ((this.foregroundColor.getRGB() == localForegroundHighlightAction.foregroundColor.getRGB()) && (this.scope == localForegroundHighlightAction.scope));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ForegroundHighlightAction localForegroundHighlightAction = (ForegroundHighlightAction)super.clone();
    localForegroundHighlightAction.setForegroundColor(new Color(getForegroundColor().getRGB(), true));
    return localForegroundHighlightAction;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1;
      String str2 = paramXMLableReader.getTagName();
      if ("Foreground".equals(str2))
        if ((str1 = paramXMLableReader.getAttr("color")) != null)
          setForegroundColor(new Color(Integer.parseInt(str1), true));
      if ("Scope".equals(str2))
        if ((str1 = paramXMLableReader.getAttr("val")) != null)
          setScope(Integer.parseInt(str1));
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if ((this.foregroundColor != null) && (this.foregroundColor != Color.black))
      paramXMLPrintWriter.startTAG("Foreground").attr("color", getForegroundColor().getRGB()).end();
    if (getScope() != 0)
      paramXMLPrintWriter.startTAG("Scope").attr("val", getScope()).end();
  }
}